package com.work.crops.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.work.crops.dao.CropsInfoIndexMapper;
import com.work.crops.pojo.CropsInfoIndex;
import com.work.crops.pojo.CropsParam;
import com.work.crops.service.CropsIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class CropsIndexServiceImpl implements CropsIndexService {

    @Autowired
    private CropsInfoIndexMapper cropsInfoIndexMapper;

    /**
     * 根据id查询农作物指标
     * @param id  农作物id
     * @return
     */
    @Override
    public List<CropsInfoIndex> findById(Integer id,String stage) {
        return cropsInfoIndexMapper.findByCropsId(id,stage);
    }

    /**
     * 分页查询
     * @param page  当前页
     * @param size  每页大小
     * @param cropsParam    查询条件
     * @return
     */
    @Override
    public PageInfo findByPage(Integer page, Integer size, CropsParam cropsParam) {

        PageHelper.startPage(page,size);
         List<CropsInfoIndex> list =  cropsInfoIndexMapper.findByPage(cropsParam);
        return new PageInfo(list);
    }

    /**
     * 根据id修改农作物指标
     * @param cropsInfoIndex   指标数据
     * @return
     */
    @Override
    public Integer updateById(CropsInfoIndex cropsInfoIndex) {

        return cropsInfoIndexMapper.updateByPrimaryKeySelective(cropsInfoIndex);
    }

    /**
     * 添加农作物指标
     * @param cropsInfoIndex
     */
    @Override
    public void add(CropsInfoIndex cropsInfoIndex) {
        cropsInfoIndexMapper.insertSelective(cropsInfoIndex);
    }


}



